package com.yuneec.fly.presenters;

import com.yuneec.fly.GlobalParams;

/**
 * Created by jw.gu on 2016/10/26 0026.
 */

public class CameraTaskPresenter {
    public static final int TASK_COMMAND_MAX_RETRY_TIMES = 8;

    private static volatile CameraTaskPresenter instance;
    private CameraPresenter cameraPresenter;

    private CameraTaskPresenter() {
        super();
    }

    public static CameraTaskPresenter getInstance() {
        if (instance == null) {
            synchronized (CameraTaskPresenter.class) {
                if (instance == null) {
                    instance = new CameraTaskPresenter();
                }
            }
        }
        return instance;
    }

    public void takePhoto() {
        if (cameraPresenter == null && GlobalParams.cameraType != null) {
            switch (GlobalParams.cameraType) {
                case CGO3P:
                    cameraPresenter = Cgo3ProPresenter.getInstance();
                    break;
                case CGO4:
                    cameraPresenter = Cgo4Presenter.getInstance();
                    break;
            }
        }
        if (cameraPresenter != null) {
            cameraPresenter.takePhotoWithRetryTimes();
        }
    }

    public void startRecord(int recordTime) {
        if (cameraPresenter == null && GlobalParams.cameraType != null) {
            switch (GlobalParams.cameraType) {
                case CGO3P:
                    cameraPresenter = Cgo3ProPresenter.getInstance();
                    break;
                case CGO4:
                    cameraPresenter = Cgo4Presenter.getInstance();
                    break;
            }
        }
        if (cameraPresenter != null) {
            cameraPresenter.startRecordWithRetryTimes(recordTime);
        }
    }
}
